home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS14.ADF
/
Progs
/
CRLF.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-01-28
|
3KB
|
112 lines
/****************************************************************
** **
** Program Name - CRLF **
** **
** Function - Add or Remove CR's from a text file **
** **
** Input file - Specified on command line **
** **
** Output fils - Specified on command line **
** **
** Commands - A = Add CR's R = Remove CR's **
** Entered on Command Line **
** **
** Written by - John Frickson **
** **
** Date Written - 31-Aug-86 **
** **
** Known Bugs - None **
** **
** Maintenance - None **
** **
****************************************************************/
#include "stdio.h"
FILE *input_file, *fopen ();
FILE *output_file, *fopen ();
main (argc, argv)
int argc;
char *argv[];
{
if (argc != 4)
{
printf ("Usage - CRLF inputfile outputfile A|R\n");
printf (" A = Add CR's R = Remove CR's\n");
exit (0);
}
if (chkcmd (argv[3]) != NULL)
{
opnfil (argv[1], argv[2]);
fixfil (argv[3]);
clsfil ();
}
exit (0);
}
chkcmd (cmd)
char cmd[];
{
int result = 0;
if (cmd[0] == 'A' || cmd[0] == 'a' || cmd[0] == 'R' || cmd[0] == 'r')
result = 1;
else
{
printf ("Usage - CRLF inputfile outputfile A|R\n");
printf (" A = Add CR's R = Remove CR's\n");
}
return (result);
}
opnfil (infile, outfile)
char infile[], outfile[];
{
input_file = fopen (infile, "r");
if (input_file == NULL)
printf ("Input File - %s cannot be opened\n", infile);
if (input_file != NULL)
{
output_file = fopen (outfile, "w");
if (output_file == NULL)
printf ("Output File - %s cannot be opened\n", outfile);
}
}
clsfil ()
{
if (input_file != NULL)
fclose (input_file);
if (output_file != NULL)
fclose (output_file);
}
fixfil (cmd)
char cmd[];
{
char c;
if (input_file != NULL && output_file != NULL)
{
while ( ! feof (input_file))
{
c = getc (input_file);
if ( ! feof (input_file))
{
if (cmd[0] == 'A' || cmd[0] == 'a')
{
putc (c, output_file);
if (c == '\n')
putc ('\r', output_file);
}
else if (c != '\r')
putc (c, output_file);
}
}
}
}